﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using ElectronicCommerce.Framework.Configuration;
using ElectronicCommerce.Framework.Configuration.Attributes;

namespace ElectronicCommerce.Framework.Data.Configuration
{
    [ConfigFile("DataFilter.config")]
    [XmlRoot("FilterList")]
    public class DataFilterConfiguration
    {
        [XmlElement("Host")]
        public List<FilterHost> Hosts { get; set; }
    }

    public class FilterHost
    {
        [XmlAttribute("type")]
        public string HostType
        {
            get;
            set;
        }

        [XmlIgnore]
        public Type TypeInfo
        {
            get
            {
                return Type.GetType(HostType);
            }
        }

        [XmlAttribute("adminFilter")]
        public string AdminFilterType
        {
            get;
            set;
        }


        [XmlAttribute("customerFilter")]
        public string CustomerFilterType
        {
            get;
            set;
        }

        [XmlIgnore]
        public FilterEnum AdminFilterEnum
        {
            get
            {
                return (FilterEnum)Enum.Parse(typeof(FilterEnum), AdminFilterType);
            }
        }

        [XmlIgnore]
        public FilterEnum CustomerFilterEnum
        {
            get
            {
                return (FilterEnum)Enum.Parse(typeof(FilterEnum), CustomerFilterType);
            }
        }
    }

    public static class DataFilterConfigHelpr
    {
        public static DataFilterConfiguration DataFilterConfig
        {
            get
            {
                return ConfigManager.GetConfig<DataFilterConfiguration>();
            }
        }
    }
}
